<?php
/*
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
*/
$userid = get_loggedin_userid();
//$userid = get_input('user_id');
// Get variables
$type = get_input('type');
$client_id = get_input('client_id');

/*

return array(
            'guid' => $this->getGUID(),
            'sender' => $sender ? userToArray($sender, $this->client_id, FALSE) : NULL,
            'refererid' => $this->referer_id,
            'response' => $this->response,
            'status' => $this->status,
            'time' => $this->getTimeCreated()
        );

*/

function to_friend_request_array($request) {
	return array(
            'guid' => $request->id,
            'sender' => $request->user_id ? userToArray(get_user($request->user_id), $client_id, FALSE) : NULL,
            'refererid' => $request->id,
            'response' => 0,
            'status' => 0,
            'time' => $request->timestamp,
            'type' => 'friend_request'
        );
}

if($client_id == OPINIONS) {
	$requests = get_opinions_friend_requests($userid);
} else {
	$requests = get_whiteboard_friend_requests($userid);
}

$results = array();
foreach ($requests as $request) {
	//print '<pre>';
	//print_r($request);
    $results[] = to_friend_request_array($request);
}

echo json_encode(export_result(200, $results));
?>